class Solution(object):
    def findKDistantIndices(self, nums, key, k):
        st = []
        last = 0
        n = len(nums)
        for i, num in enumerate(nums):
            if num == key:
                for j in range(max(last, i - k), min(i + k + 1, n)):
                    if not st:
                        st.append(j)
                    else:
                        if j > st[-1]:
                            st.append(j)
                last = min(i + k + 1, n)
        return st